#include "lightsettingsform.h"
#include "ui_lightsettingsform.h"
#include <QPainter>
#include <QStyleOption>

LightSettingsForm::LightSettingsForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::LightSettingsForm)
{
    ui->setupUi(this);
    this->setProperty("form","backgroundform");
    ui->leftBorderForm->SetLabelIcon("lightSettings");
    this->setFixedHeight(340);
    
    // 连接右侧表单自己的滑块值变化信号到对应的槽函数
    // 这样当用户拖动右侧的滑块时，标签也会同步更新
    connect(ui->horizontalSlider_gain, &QSlider::valueChanged, this, &LightSettingsForm::updateGain);
    connect(ui->horizontalSlider_gamma, &QSlider::valueChanged, this, &LightSettingsForm::updateGamma);
    connect(ui->horizontalSlider_gainImage, &QSlider::valueChanged, this, &LightSettingsForm::updateGainImage);
}

LightSettingsForm::~LightSettingsForm()
{
    delete ui;
}

void LightSettingsForm::UpdateShowType(int type)
{
    ui->leftBorderForm->UpdateShowType(type);
}

void LightSettingsForm::paintEvent(QPaintEvent *event)
{
    QStyleOption opt;
    opt.init(this);
    QPainter painter(this);
    style()->drawPrimitive(QStyle::PE_Widget,&opt,&painter,this);
    QWidget::paintEvent(event);
}

void LightSettingsForm::updateLedValue(int value)
{
    ui->label_ledValue->setText(QString::number(value/ 100.0).append("%"));
}

void LightSettingsForm::updateGain(int value)
{
    ui->label_gain->setText(QString::number(value));
}

void LightSettingsForm::updateGamma(int value)
{
    ui->label_gamma->setText(QString::number(value));
}

void LightSettingsForm::updateGainImage(int value)
{
    ui->label_gainImage->setText(QString::number(value));
}

void LightSettingsForm::on_toolButton_contractExpand_clicked(bool checked)
{
    ui->widget_hide->setHidden(!checked);
    if(checked)
        this->setFixedHeight(340);
    else
        this->setFixedHeight(70);
}
